#include "Level.h"
#include "DataManager.h"

//------------------------------------------------------------>
Level::Level(void)
:
	_levelSceneNode(0),
	_floor(0),
	_leftWall(0),
	_rightWall(0),
	_frontWall(0),
	_backWall(0)
{
	dataManager = DataManager::getDataManagerAsSingleton();
	createSceneNodes();
}

//------------------------------------------------------------>
Level::~Level(void)
{
}

//------------------------------------------------------------>
void Level::createSceneNodes()
{

	_levelSceneNode = dataManager->getSceneManager()->getRootSceneNode()->createChildSceneNode();
	_floor		= _levelSceneNode->createChildSceneNode();
	_leftWall	= _levelSceneNode->createChildSceneNode();
	_rightWall	= _levelSceneNode->createChildSceneNode();
	_backWall	= _levelSceneNode->createChildSceneNode();
	_frontWall	= _levelSceneNode->createChildSceneNode();

	//FLOOR
	Ogre::Plane planeFloor(Ogre::Vector3::UNIT_Y, 0);
	Ogre::MeshManager::getSingleton().createPlane("floor", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, planeFloor, 150,150,20,20,true,1,10,10,Ogre::Vector3::UNIT_Z);
	Ogre::Entity* ent = dataManager->getSceneManager()->createEntity("floorEntity", "floor");
    _floor->attachObject(ent);
    ent->setMaterialName("grassFloor");
    ent->setCastShadows(false);

	//LEFT WALL
	Ogre::Plane planeLeftWall(Ogre::Vector3::UNIT_X, 0);
	Ogre::MeshManager::getSingleton().createPlane("leftWall", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, planeLeftWall, LEVEL_SIZE, LEVEL_SIZE/2,5,5,true,1,5,2.5,Ogre::Vector3::UNIT_Y);
	ent = dataManager->getSceneManager()->createEntity("leftWallEntity", "leftWall");
    _leftWall->attachObject(ent);
    ent->setMaterialName("rockwall");
    ent->setCastShadows(false);

	//RIGHT WALL
	Ogre::Plane planeRightWall(Ogre::Vector3::NEGATIVE_UNIT_X, 0);
	Ogre::MeshManager::getSingleton().createPlane("rightWall", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, planeRightWall, LEVEL_SIZE, LEVEL_SIZE/2,5,5,true,1,5,2.5,Ogre::Vector3::UNIT_Y);
	ent = dataManager->getSceneManager()->createEntity("rightWallEntity", "rightWall");
    _rightWall->attachObject(ent);
    ent->setMaterialName("rockwall");
    ent->setCastShadows(false);

	//FRONT WALL
	Ogre::Plane planeFrontWall(Ogre::Vector3::UNIT_Z, 0);
	Ogre::MeshManager::getSingleton().createPlane("frontWall", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, planeFrontWall, LEVEL_SIZE, LEVEL_SIZE/2,5,5,true,1,5,2.5,Ogre::Vector3::UNIT_Y);
	ent = dataManager->getSceneManager()->createEntity("frontWallEntity", "frontWall");
    _frontWall->attachObject(ent);
    ent->setMaterialName("rockwall");
    ent->setCastShadows(false);


	//BACK WALL
	Ogre::Plane planeBackWall(Ogre::Vector3::NEGATIVE_UNIT_Z, 0);
	Ogre::MeshManager::getSingleton().createPlane("backWall", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, planeBackWall, LEVEL_SIZE, LEVEL_SIZE/2,5,5,true,1,5,2.5,Ogre::Vector3::UNIT_Y);
	ent = dataManager->getSceneManager()->createEntity("backEntity", "backWall");
    _backWall->attachObject(ent);
    ent->setMaterialName("rockwall");
    ent->setCastShadows(false);


	_leftWall->translate(Ogre::Vector3(-LEVEL_SIZE/2,0,0));
	_rightWall->translate(Ogre::Vector3(LEVEL_SIZE/2,0,0));
	_frontWall->translate(Ogre::Vector3(0,0,-LEVEL_SIZE/2));
	_backWall->translate(Ogre::Vector3(0,0,LEVEL_SIZE/2));

}